package cn.csxw.openchina.dagger2.presenter;

import javax.inject.Inject;

import cn.csxw.openchina.entity.bean.NewsBean;
import cn.csxw.openchina.entity.bean.OsChinaBean;
import cn.csxw.openchina.ui.activity.NewsDetailActivity;
import retrofit2.Call;

/**
 * Created by hp on 2017/1/15.
 */

public class NewsDetailActivityPresenter extends BasePresenter {
    NewsDetailActivity mNewsDetailActivity;

    @Inject
    public NewsDetailActivityPresenter(NewsDetailActivity newsDetailActivity) {
        mNewsDetailActivity = newsDetailActivity;
    }

    @Override
    protected void processData(OsChinaBean data) {
        if(data!=null){
            NewsBean news = data.news;
            if (news!=null) {
                mNewsDetailActivity.doNetWork(news);
            }
        }
    }

    @Override
    public void callNetWork(Object... params) {
        if(params.length!=1||!(params[0] instanceof String)){
            throw new IllegalArgumentException("必需是一个String类型的参数");
        }
        Call<OsChinaBean> newsDetailInfo = mOsChinaServer.getNewsDetailInfo((String) params[0]);
            newsDetailInfo.enqueue(mCallback);
    }
}
